<template>
    <h2>添加</h2>
    <table border="1">
        <tr>
            <td>科室名称</td>
            <ts>
                <input type="text" v-model="info.D_Name"/>
            </ts>
        </tr>
        <tr>
            <td>科室介绍</td>
            <ts>
                <input type="text" v-model="info.D_Info"/>
            </ts>
        </tr>
        <tr>
            <td>
                <input type="button" value="添加" @click="Add"/>
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
    import {ref,onMounted} from 'vue';
    import axios from 'axios';
    import {useCounterStore} from '../stores/counter.ts';
    const Cstore=useCounterStore();

    const info=ref({
        D_Name: "",
        D_Info: ""
    });

    onMounted(()=>{
        GetUserType();
    })

    console.log(Cstore.Username);

    const Add=()=>{
        if(UserType.value=="用户"){
            alert('当前用户没有权限进行该操作');
            return;
        }
        axios.post("https://localhost:7010/api/Dept/AddDept",{
            D_Name:info.value.D_Name,
            D_Info:info.value.D_Info,
            D_AddUser:Cstore.Username
        })
        .then(res=>{
            if(res.data>0){
                alert('添加成功');
                
            }
            else if(res.data==-1){
                alert('已存在');
            }
            else{
                alert('添加失败');
            }
        })
    }

    const UserType=ref("");

    const GetUserType=()=>{
        axios.get("https://localhost:7010/api/Dept/GetUserType",{
            params:{
                Uname:Cstore.Username
            }
        })
        .then(res=>{
            console.log(res.data);
            UserType.value=res.data[0];
        })
    }

</script>
